<?php

namespace Gnway\Ticket\Rest\Annotation;

use Doctrine\Common\Annotations\Annotation\Target;
use Doctrine\Common\Annotations\Annotation\Attribute;
use Doctrine\Common\Annotations\Annotation\Attributes;

/**
 * PackageScan Annotation
 *
 * @Annotation
 * @Target("CLASS")
 * @Attributes({
 *     @Attribute("packages", type="array", required=true),
 *     @Attribute("extension", type="string", required=false),
 * })
 * @author zushaolong
 * @mail zushaolong@gmail.com
 */
final class PackageScan
{

  /**
   * Packages
   *
   * @var array
   */
  private array $packages = [];

  /**
   * @var string
   */
  private string $extension = 'php';

  /**
   * PackageScan constructor.
   *
   * @param array $values
   */
  public function __construct(array $values)
  {
    if (isset($values['packages'])) {
      foreach ((array)$values['packages'] as $package) {
        $package && $package = realpath($package);
        $package && $this->packages[] = $package;
      }
    }
    if (isset($values['extension'])) {
      $this->extension = (string)$values['extension'];
    }
  }

  /**
   * @return array
   */
  public function getPackages(): array
  {
    return $this->packages;
  }

  /**
   * @return string
   */
  public function getExtension(): string
  {
    return $this->extension;
  }
}